import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
import {interceptor} from "@/api/config/interceptor.ts";
import {Response} from "@/api/interface/auth.ts";


const requestInstance = axios.create({
    // 设置超时时间（10s）
    baseURL: '',
    timeout: 10000,
    // 跨域时候允许携带凭证
    withCredentials: true
})
interceptor(requestInstance)

function requestWrap(baseUrl: string = '') {
    return (params: AxiosRequestConfig) => requestInstance({
        ...params,
        url: baseUrl.concat(params.url || '').replace(/\/\//g, '/')
    }).then((res: AxiosResponse<Response<any>>) => res.data)
}

// 默认请求实例
export const request = requestWrap("/")

